package com.ssyc.student.activity;

import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;

import com.ssyc.common.base.BaseActivity;
import com.ssyc.common.base.SpKeys;
import com.ssyc.common.utils.SPUtil;
import com.ssyc.common.utils.UiUtils;
import com.ssyc.common.view.TypeTextView;
import com.ssyc.student.R;

/**
 * 宠物最后展示界面
 * Created by Kevin on 2018/4/18.
 */

public class StudentGetpetLastActivity extends BaseActivity implements View.OnClickListener{

    //GO按钮
    private ImageView iv_go;

    //显示的文字
    private TypeTextView tvChoosePet;

    //小星星1
    private ImageView iv_littleStar_one;

    //小星星2
    private ImageView iv_littleStar_two;

    //显示宠物图像的ImageView
    private ImageView lvPet;

    //四种宠物类型的集合
    private int[] pets = {R.drawable.student_flicker_dog,R.drawable.student_flicker_cat,
            R.drawable.student_flicker_monster, R.drawable.student_flicker_panda};

    //返回按钮
    private ImageView iv_back;

    @Override
    protected boolean isNeedShowTitle() {
        return false;
    }

    @Override
    protected String setTitleText() {
        return null;
    }

    @Override
    protected int getContentLayout() {

        return R.layout.student_activity_getpet_last;
    }

    @Override
    protected void init() {

       //初始化视图
        initview();
        showContent();
    }

    /**
     * 初始化视图的方法
     */
    private void initview() {

        iv_back = findViewById(R.id.iv_back);
        iv_back.setOnClickListener(this);

        iv_littleStar_one = findViewById(R.id.iv_littleStar_one);
        iv_littleStar_two = findViewById(R.id.iv_littleStar_two);

        tvChoosePet = findViewById(R.id.tv_choose_pet);
        tvChoosePet.start(getResources().getString(R.string.st_pet_last));


        lvPet = findViewById(R.id.lv_pet);
        lvPet.setImageResource(pets[SPUtil.getInt(this, SpKeys.PETTYPE)-1]);

        iv_go = findViewById(R.id.iv_go);
        iv_go.setOnClickListener(this);

        //闪烁动画
        startFlick(iv_littleStar_one);
        startFlick(iv_littleStar_two);
    }



    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.iv_go) {
            //跳转页面
            UiUtils.startActivity(this, StudentMainActivity.class);
            finish();
        }else if(id == R.id.iv_back){
            finish();
        }

    }



    /**
     * 闪烁动画
     *
     * */
    private void startFlick(View view){
        if(null == view){
            return;
        }
        Animation alphaAnimation = new AlphaAnimation(1, 0.4f);
        alphaAnimation.setDuration(300);
        alphaAnimation.setInterpolator(new LinearInterpolator());
        alphaAnimation.setRepeatCount(Animation.INFINITE);
        alphaAnimation.setRepeatMode(Animation.REVERSE);
        view.startAnimation(alphaAnimation);
    }



    /**
     * 生命周期中取消打字机效果
     */
    @Override
    protected void onDestroy() {
        if (null != tvChoosePet) {
            tvChoosePet.stop();
        }
        super.onDestroy();
    }
}
